@model IEnumerable<ContactManager.Models.Contact>
@using ContactManager.Authorization;


@{
    ViewData["Title"] = "Index";
}

<h2>Index</h2>

<p>
    <a asp-action="Create">Create New</a>
</p>

@*TODO-Rick - Remove address, email, zip from Index page, leave them on the Details page.
    Add owner name.*@

<table class="table">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.Address)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.City)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Email)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Name)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.State)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Zip)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Status)
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.Address)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.City)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Email)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Name)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.State)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Zip)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Status)
                </td>
                <td>
                    @if (await AuthorizationService.AuthorizeAsync(User,
                                                       item, ContactOperations.Update))
                    {
                        <a asp-action="Edit" asp-route-id="@item.ContactId">Edit</a><text> | </text>
                    }
                    <a asp-action="Details" asp-route-id="@item.ContactId">Details</a>
                    @if (await AuthorizationService.AuthorizeAsync(User,
                                                         item, ContactOperations.Delete))
                    {
                        <text> | </text>
                        <a asp-action="Delete" asp-route-id="@item.ContactId">Delete</a>
                    }
                </td>
            </tr>
        }
    </tbody>
</table>
